﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class bb : System.Web.UI.Page
    {
        string path = System.Web.HttpContext.Current.Server.MapPath("/bb.html");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string returnstr = "请联系QQ-9021616 购买注册";
                if (File.Exists(path))
                {
                    StreamReader myreader = File.OpenText(path);//读取记事本文件
                    try
                    {
                        returnstr = myreader.ReadToEnd();//从当前位置读取到文件末尾
                        string[] s = returnstr.Replace("\r\n", "").Split(';');
                        num.Text = s[0];
                        webnum.Text = s[1];
                        second.Text = s[2];
                        min.Text = s[3];
                        max.Text = s[4];
                        if (s[5] == "1")
                        {
                            run.Checked = true;
                        }
                        else
                        {
                            run.Checked = false;
                        }
                    }
                    catch (Exception err)
                    {
                        Response.Write(err.Message);
                    }
                    finally
                    {
                        if (myreader != null)
                            myreader.Close();
                    }
                }
            }
        }

        protected void bt_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                sb.Append(num.Text + ";");
                sb.Append(webnum.Text + ";");
                sb.Append(second.Text + ";");
                sb.Append(min.Text + ";");
                sb.Append(max.Text + ";");
                if (run.Checked)
                {
                    sb.Append("1;");
                }
                else
                {
                    sb.Append("0;");
                }
                Set(sb.ToString());
                Response.Redirect("bb.aspx");
            }
            catch
            {
                Response.Write("输入有错误,请检查.只能输入英文输入法状态下的数字");
            }
        }

        protected void Set(string cs)
        {
            //写入
            StreamWriter sr = null;
            try
            {
                sr = File.CreateText(path);
                sr.WriteLine(cs);
            }
            catch (Exception err)
            {
                Response.Write(err.Message);
            }
            finally
            {
                if (sr != null)
                    sr.Close();
            }
        }
    }
}